package com.estronger.shopmanage.ui.order.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.estronger.shopmanage.R;
import com.estronger.shopmanage.ui.order.bean.OrderAttributeBean;
import com.estronger.shopmanage.ui.order.bean.TaocanBean;
import com.estronger.shopmanage.ui.order.bean.TaocanitemBean;
import com.estronger.shopmanage.utils.ConvertUtils;

import java.util.ArrayList;

/**
 * Created by DingYG on 2017-07-28.
 */

public class TaoCanItemAdapter extends BaseAdapter {
    private ArrayList<TaocanitemBean> mList = new ArrayList<>();
    Activity mContext;

    public TaoCanItemAdapter(Activity context) {
        mContext = context;
    }
    public void appendData(ArrayList<TaocanitemBean> data){
        if(data==null){return;}else{mList.clear();}
        mList.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        if (mList != null)
            return mList.size();
        else
            return 0;
    }

    @Override
    public TaocanitemBean getItem(int position) {
        // TODO Auto-generated method stub
        if (mList == null || mList.size() <= 0)
            return null;
        else
            return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        final ListItemView ltv;
        final TaocanitemBean item = mList.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.view_taocanshux, null);
            ltv = new ListItemView(convertView);
            convertView.setTag(ltv);
        } else {
            ltv = (ListItemView) convertView.getTag();
        }
        try {
            if(mList.size()-1 == position){
                ltv.ivfGed.setVisibility(View.GONE);
            }else{
                ltv.ivfGed.setVisibility(View.VISIBLE);
            }
            ltv.tvfName.setText(ConvertUtils.formatNull(item.getAttName()));
            if(item.getAttVaule() != null && !item.getAttVaule().equals("")){
                ltv.tvfTcShux.setText(item.getAttVaule());
            }else{
                ltv.tvfTcShux.setText("");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

    public class ListItemView {
        TextView tvfName;
        TextView tvfTcShux;
        RelativeLayout rlfTaocanShuxItem;
        ImageView ivfGed;
        public ListItemView(View view){
            this.tvfName = (TextView) view.findViewById(R.id.tvfItemName);
            this.tvfTcShux = (TextView) view.findViewById(R.id.tvfTcShux);
            this.rlfTaocanShuxItem = (RelativeLayout) view.findViewById(R.id.rlfTaocanItem);
            this.ivfGed = (ImageView) view.findViewById(R.id.ivfBottom);
        }
    }
}
